<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  	<link type="text/css" rel="stylesheet" href="../../template/css/weui.css" />
    	<link type="text/css" rel="stylesheet" href="../../template/css/weui2.css" />
    	<link type="text/css" rel="stylesheet" href="../../template/css/weui3.css" />
        <meta charset="utf-8">
		<meta name="keywords" content="" />
		<meta name="description" content="" />
		<meta content="width=device-width, minimum-scale=1,initial-scale=1, maximum-scale=1, user-scalable=1" id="viewport" name="viewport" />
		<meta content="yes" name="apple-mobile-web-app-capable" />
		<meta content="black" name="apple-mobile-web-app-status-bar-style" />
		<meta content="telephone=no" name="format-detection" />
		<link type="text/css" rel="stylesheet" href="../../template/css/com/com.css"/>
		<link type="text/css" rel="stylesheet" href="../../template/css/list/style.css"/>
        <link rel="stylesheet" href="../../resource/weuimin.css" />
		<script src="../../template/js/jquery.js"></script>
		<script src="../../template/js/com/com.js"></script>
		<script src="../../template/js/com/template.js"></script>
		<script src="../../resource/my.js"></script>
		<script src="../../script/api.js"></script>
		<script type="text/javascript" src="../../script/constants.js"></script>
    <script src="../../template/js/zeptomin.js"></script>
            <script type="text/javascript" src="../../script/aes.js"></script>
	<script type="text/javascript" charset="UTF-8" src="../../script/naes.js"></script>
	<script type="text/javascript" src="../../script/modeecb.js"></script>
        <script type="text/javascript" src="../../script/tmd5.js"></script>

        <link rel="stylesheet" href="../../resource/jinsuistyle.css" />
        <style>
        	.img80 img{height:100px;}
        </style>
     <script type="text/javascript">
     var qdm = "";
     var xpage = 1;
     var apage = 1;
	 apiready=function(){
	 if(api.systemType == "ios"){
	   document.getElementById("statusBar").style.background = "#298cb4";
	}
	 $api.fixStatusBar( $api.dom('header') );
     var header = $api.byId('jsheader');
     if(api.systemType=='ios'){
 			$api.fixIos7Bar(header);
 		}
// 		else{
// 			$api.fixStatusBar(header);
// 		}
		 api.sendEvent({
		    name: 'close',
		    extra: {
		        key: 1
		    }
		 });
	    qdm = api.pageParam.qdm;
	    var dmc = api.pageParam.dmc;
	    var i = api.pageParam.i;
	    var data = $api.getStorage('spxx');
	    var leftList = "";
	    
        for(var i=0;i<data.length;i++) {
			if(qdm == data[i].ddm){
				leftList += "<li class='typea typeselected' onclick=\"select('"+data[i].ddm+"',1,this,'"+ data[i].dmc + "')\">"+data[i].dmc+"</li>";
			}else{
				leftList += "<li class='typea' onclick=\"select('"+data[i].ddm+"',1,this,'"+ data[i].dmc + "')\">"+data[i].dmc+"</li>";
			}
		}
	    $("#secli").html(leftList);

	    $("#title").html(dmc);
		$("#span_page").change(function(){
			select(qdm,$("#span_page").val());
		});
		select(qdm,1);
      }


	 function select(xdm,page,e,title){
 		if("undefined" != typeof e){
 			$(".typea").attr('class','typea');
 			e.setAttribute("class", "typea typeselected");
 		}
 		qdm = xdm;
 		xpage = parseInt(page);
 		if("undefined" != typeof title){
			$("#title").html(title);
		}
		$("#loadingToast").show();
		var callback = function(ret, err){
            //console.log(JSON.stringify(ret));
            $("#loadingToast").hide();
	        showList(ret,page);
        }
        var content = {"dm":xdm,"page":page};
        apiAjax(JSON.stringify(content),url.zcxjurl,callback);
 	}

 	   function showList(dd,page){
 	  	console.info("1");
 	      var html = "";
    	  var data = eval("("+ dd.json +")");
    	  if(data.sps.length > 0){
    	  for(var i=0;i<data.sps.length;i++){
    		  var kc = "";
    		  var className = "";
    		  if(data.sps[i].kc <= 0){
    			kc = "<b>(无货)</b>";
    		  }
    		  if(data.sps[i].isnew == "1"){
    			className = "goodNews";
    		  }
    		if(getCookie(data.sps[i].dm) != null){	//已经点击过的新品不要提示图标
				className = "";
			}
    	  		var a = data.sps[i].pic;

			if(data.sps[i].dm=='2701T999901124'||data.sps[i].dm=='2701T999901115'||data.sps[i].dm=='2701T999901095'||data.sps[i].dm=='2701T999901096'||data.sps[i].dm=='2701T999901161'||data.sps[i].dm=='2701T999901114'
			||data.sps[i].dm=='2701T999901097'){
			
    	  		html +="<a href=\"javaScript:void(0)\" class=\""+ className + "\">"
					 +"<table width=\"100%\"><tr>"
					 +"<td rowspan=\"2\">"
					 +"<div class=\"img80\">"
					    +"<img src=\""+ a.substring(0,a.lastIndexOf('.'))+"_bak.jpg"+"\" onclick=\"show('" + data.sps[i].dm + "\')\"/>"
						+"</div></td>"
					+"<td><span class=\"name\" onclick=\"show('" + data.sps[i].dm + "\')\">"+"(折扣)"+(data.sps[i].mc + kc) + "</span> </td>"
					+"<td rowspan=\"2\" width=\"16%\">"
					+"<input type=\"button\" class=\"pxui-light-button addtocart\" style=\"width:40px;padding:5px;\" id=\"xgButton\""
					+"value=\"选购\" onclick=\"subtj('"+ data.sps[i].mc + "','" + data.sps[i].price + "','1','"+ data.sps[i].dm+"','"+data.sps[i].kc+"') \"/>"
					+"</td>"
					+"</tr><tr>"
					+"<td style=\"padding-left:12px;\"><span class=\"price\">￥"+data.sps[i].price+"</span>&nbsp;&nbsp;(四川省内包邮，省外另加邮费12元)</td>"
					+"</tr></table></a>";
			}else{
			
    	  		html +="<a href=\"javaScript:void(0)\" class=\""+ className + "\">"
					 +"<table width=\"100%\"><tr>"
					 +"<td rowspan=\"2\">"
					 +"<div class=\"img80\">"
					    +"<img src=\""+ a +"\" onclick=\"show('" + data.sps[i].dm + "\')\"/>"
						+"</div></td>"
					+"<td><span class=\"name\" onclick=\"show('" + data.sps[i].dm + "\')\">"+"(折扣)"+ (data.sps[i].mc + kc) + "</span> </td>"
					+"<td rowspan=\"2\" width=\"16%\">"
					+"<input type=\"button\" class=\"pxui-light-button addtocart\" style=\"width:40px;padding:5px;\" id=\"xgButton\""
					+"value=\"选购\" onclick=\"subtj('"+ data.sps[i].mc + "','" + data.sps[i].price + "','1','"+ data.sps[i].dm+"','"+data.sps[i].kc+"') \"/>"
					+"</td>"
					+"</tr><tr>"
					+"<td style=\"padding-left:12px;\"><span class=\"price\">￥"+data.sps[i].price+"</span>&nbsp;&nbsp;(四川省内包邮，省外另加邮费12元)</td>"
					+"</tr></table></a>";
					
			}

    	  }
    	  $("#js-goodlist").html(html);
    	  apage = data.ys;
    	  $("#span_all").html(page + "/" + data.ys);
        	  var select_option = "";
        	  for(var i=1;i<=data.ys;i++){
        		  if(i == page){
        		 	select_option +="<option value=\""+ i + "\" selected=\"selected\">"+ i + "/" + data.ys +"</option>";
        		  }else{
        			select_option +="<option value=\""+ i + "\">"+ i + "/" + data.ys +"</option>";
        		  }
        	  }
        	  $("#span_page").html(select_option);
    	  }else {
    		 $("#js-goodlist").html("<div style=\"padding:10px;width:100%;text-align:center;\">\暂时没有数据！\</div>");
    		 $("#span_all").html("1/0");
    		$("#span_page").html("");
    	  }
 	   }

	 function show(dm){
     	SetCookie(dm,dm);
     	api.openWin({
				    name: 'detail',
				    url: './detail.html',
				    pageParam: {
				        spdm: dm
				    }
				});
     }

	 function subtj(spmc,price,sl,dm,kc){
 		//console.info(spmc+","+price+","+sl+","+dm+","+kc);
 		if(kc>0){
	 		var product =
		        {
	              'dm':dm,       //属性名用引号括起来，属性间由逗号隔开
	              'spmc': spmc,
	              'sl':sl,
	              'price':price
		        };
		     	  cart.addproduct(product);
		    api.toast({
		        msg:spmc+"已添加到购物筐"
	        });
        }else{
          api.toast({
	        msg:"库存不足"
        });
        }
 	}


        	function jpage(e){
        		if(e == 'a'){
        			if( xpage > 1){
		        		xpage = xpage-1;
		        		select(qdm,xpage);
        			}
        		}
        		if(e == 'b' ){
        			if(xpage < apage){
		        		xpage = xpage+1;
		        		select(qdm,xpage);
        			}
        		}
        	}

       function closeWin(){
         api.closeWin();
        }


       function reMain(){
			api.openWin({
				    name: 'main',
				    url: './main.html',
				    pageParam: {

				    }
			});
        }

        utils = {
		    setParam : function (name,value){
		        localStorage.setItem(name,value)
		    },
		    getParam : function(name){
		        return localStorage.getItem(name)
		    }
		}

		product={
		    dm:0,
		    spmc:"",
		    sl:0,
		    price:0.00,
		};

			orderdetail={
			  //  username:"",
			  //  phone:"",
			  //  address:"",
			  //  zipcode:"",
			    totalNumber:0,
			    totalAmount:0.00
			}

			cart = {
			    //向购物车中添加商品
			    addproduct:function(product){
			        var ShoppingCart = utils.getParam("ShoppingCart");
			        if(ShoppingCart==null||ShoppingCart==""){
			                        //第一次加入商品
			            var jsonstr = {"productlist":[{"dm":product.dm,"spmc":product.spmc,"sl":product.sl,"price":product.price}],"totalNumber":product.sl,"totalAmount":(product.price*product.sl)};
			            utils.setParam("ShoppingCart",JSON.stringify(jsonstr));
			        }else{
			            var jsonstr = JSON.parse(ShoppingCart);
			            var productlist = jsonstr.productlist;
			            var result=false;
			            //查找购物车中是否有该商品
			            for(var i in productlist){
			                if(productlist[i].dm==product.dm){
			                    productlist[i].sl=parseInt(productlist[i].sl)+parseInt(product.sl);
			                    result = true;
			                }
			            }
			            if(!result){
			                //没有该商品就直接加进去
			                productlist.push({"dm":product.dm,"spmc":product.spmc,"sl":product.sl,"price":product.price});
			            }
			                        //重新计算总价
			            jsonstr.totalNumber=parseInt(jsonstr.totalNumber)+parseInt(product.sl);
			//          jsonstr.totalAmount=parseFloat(jsonstr.totalAmount)+(parseInt(product.num)*parseFloat(product.price));
			            jsonstr.totalAmount=accAdd(jsonstr.totalAmount, accMul(product.sl, product.price));
			            orderdetail.totalNumber = jsonstr.totalNumber;
			            orderdetail.totalAmount = jsonstr.totalAmount;
			            //保存购物车
			            utils.setParam("ShoppingCart",JSON.stringify(jsonstr));
			        }
			    },

			    //修改给买商品数量
			    updateproductnum:function(dm,num){
			        var ShoppingCart = utils.getParam("ShoppingCart");
			        var jsonstr = JSON.parse(ShoppingCart.substr(1,ShoppingCart.length));
			        var productlist = jsonstr.productlist;

			        for(var i in productlist){
			            if(productlist[i].dm==dm){
			                jsonstr.totalNumber=parseInt(jsonstr.totalNumber)+(parseInt(num)-parseInt(productlist[i].sl));
			//              jsonstr.totalAmount=parseFloat(jsonstr.totalAmount)+((parseInt(num)*parseFloat(productlist[i].price))-parseInt(productlist[i].num)*parseFloat(productlist[i].price));
			                jsonstr.totalAmount=accAdd(jsonstr.totalAmount, accSub(accMul(num, productlist[i].price), accMul(productlist[i].sl, productlist[i].price)));
			                productlist[i].sl=parseInt(num);

			                orderdetail.totalNumber = jsonstr.totalNumber;
			                orderdetail.totalAmount = jsonstr.totalAmount;
			                utils.setParam("ShoppingCart","'"+JSON.stringify(jsonstr));
			                return;
			            }
			        }
			    },

			    //获取购物车中的所有商品
			    getproductlist:function(){
			        var ShoppingCart = utils.getParam("ShoppingCart");
			        if (!ShoppingCart) {
			                return null;
			        }
			        var jsonstr = JSON.parse(ShoppingCart.substr(1,ShoppingCart.length));
			        var productlist = jsonstr.productlist;
			        orderdetail.totalNumber = jsonstr.totalNumber;
			        orderdetail.totalAmount = jsonstr.totalAmount;
			        return productlist;
			    },

			    //获取整个购物车
			    getshopcart:function(){
			            var ShoppingCart = utils.getParam("ShoppingCart");
			            return ShoppingCart;
			    },

			    //判断购物车中是否存在商品
			    existproduct:function(id){
			        var ShoppingCart = utils.getParam("ShoppingCart");
			        var jsonstr = JSON.parse(ShoppingCart.substr(1,ShoppingCart.length));
			        var productlist = jsonstr.productlist;
			        var result=false;
			        for(var i in productlist){
			            if(productlist[i].dm==dm){
			                result = true;
			            }
			        }
			        return result;
			    },

			    // 通过id获取商品
			    getproductbyid:function(id) {
			            var ShoppingCart = utils.getParam("ShoppingCart");
			        var jsonstr = JSON.parse(ShoppingCart.substr(1,ShoppingCart.length));
			        var productlist = jsonstr.productlist;
			        var result=false;
			        for(var i in productlist){
			            if(productlist[i].dm==dm){
			                return productlist[i];
			            }
			        }
			        return null;
			    },
			    //删除购物车中商品
			    deleteproduct:function(id){
			        var ShoppingCart = utils.getParam("ShoppingCart");
			        var jsonstr = JSON.parse(ShoppingCart.substr(1,ShoppingCart.length));
			        var productlist = jsonstr.productlist;
			        var list=[];
			        for(var i in productlist){
			            if(productlist[i].dm==id){
			                jsonstr.totalNumber=parseInt(jsonstr.totalNumber)-parseInt(productlist[i].sl);
			//              jsonstr.totalAmount=parseFloat(jsonstr.totalAmount)-parseInt(productlist[i].num)*parseFloat(productlist[i].price);
			                jsonstr.totalAmount=accSub(jsonstr.totalAmount, accMul(productlist[i].sl, productlist[i].price));
			            }else{
			                list.push(productlist[i]);
			            }
			        }
			        jsonstr.productlist = list;
			        orderdetail.totalNumber = jsonstr.totalNumber;
			        orderdetail.totalAmount = jsonstr.totalAmount;
			        utils.setParam("ShoppingCart","'"+JSON.stringify(jsonstr));
			    },
			    //清空购物车
			    clear:function(){
			            utils.setParam("ShoppingCart", "");
			    }
			};


			// 两个浮点数求和
			function accAdd(num1, num2) {
			        var r1, r2, m;
			        try {
			                r1 = num1.toString().split('.')[1].length;
			        } catch(e) {
			                r1 = 0;
			        }
			        try {
			                r2 = num2.toString().split(".")[1].length;
			        } catch(e) {
			                r2 = 0;
			        }
			        m = Math.pow(10, Math.max(r1, r2));
			        // return (num1*m+num2*m)/m;
			        return Math.round(num1 * m + num2 * m) / m;
			}

			// 两个浮点数相减
			function accSub(num1, num2) {
			        var r1, r2, m;
			        try {
			                r1 = num1.toString().split('.')[1].length;
			        } catch(e) {
			                r1 = 0;
			        }
			        try {
			                r2 = num2.toString().split(".")[1].length;
			        } catch(e) {
			                r2 = 0;
			        }
			        m = Math.pow(10, Math.max(r1, r2));
			        n = (r1 >= r2) ? r1 : r2;
			        return (Math.round(num1 * m - num2 * m) / m).toFixed(n);
			}

			// 两数相除
			function accDiv(num1, num2) {
			        var t1, t2, r1, r2;
			        try {
			                t1 = num1.toString().split('.')[1].length;
			        } catch(e) {
			                t1 = 0;
			        }
			        try {
			                t2 = num2.toString().split(".")[1].length;
			        } catch(e) {
			                t2 = 0;
			        }
			        r1 = Number(num1.toString().replace(".", ""));
			        r2 = Number(num2.toString().replace(".", ""));
			        return (r1 / r2) * Math.pow(10, t2 - t1);
			}

			// 浮点数相乘
			function accMul(num1, num2) {
			        var m = 0, s1 = num1.toString(), s2 = num2.toString();
			        try {
			                m += s1.split(".")[1].length
			        } catch(e) {
			        };
			        try {
			                m += s2.split(".")[1].length
			        } catch(e) {
			        };
			        return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
			}

      function goMain(){
        api.closeWin();
      }
      
      
      function goHistory(){
			var jp = $api.getStorage("dl_phone");
				if(jp==null||jp==''||typeof(jp)==undefined||jp=='undefined'){
					api.alert({
						msg:'请登录'
			        },function(ret,err){
			        	api.openWin({
				            name: '跳转登陆',
				            url: '../login.html'
				            //url:'html/jskp/jskp.html'
			            });
			        });
				}else{
					api.openWin({
					    name: 'history.html',
					    url: 'history.html'
					    //url:'html/jskp/jskp.html'
					});
				}
			}
			
			function goBill(){
			var jp = $api.getStorage("dl_phone");
				if(jp==null||jp==''||typeof(jp)==undefined||jp=='undefined'){
					api.alert({
						msg:'请登录'
			        },function(ret,err){
			        	api.openWin({
				            name: '跳转登陆',
				            url: '../login.html'
				            //url:'html/jskp/jskp.html'
			            });
			        });
				}else{
					api.openWin({
					    name: 'bill.html',
					    url: 'bill.html'
					    //url:'html/jskp/jskp.html'
					});
				}
			}

        </script>
        <style>

         .com-footer-area {padding-top:0px;position:fixed;bottom:0;}
        .com-footer-area  img{height:auto;width:100%;} 

        	.pxui-shoes .price{margin-left:0px;}
        	.pxui-shoes{margin:0px;}
        	.typea{background-color:#f0f1eb;}
        	.typeselected{color:#436542;font-weight:700;background-color:#FFFFFF;}
        	.pxui-shoes a{width:100%;height:auto;padding:10px;}
        	#pxui-area_li li{
        		border-top:1px solid #b5bfd7;
        		text-align:center;
        		cursor: pointer;
        		font-size: 14px;
        		padding:5px;
        		line-height: 22px;
        	}
        	#pxui-area_li .first_li{
        		font-weight:700;
        		border-top-width:0px;
        		color:#fd5744;
        	}
        	.goodNews{background:#FFF url(../../template/images/xp4.png) no-repeat 94% 0px;}
        	a.pxui-light-button,
			.pxui-light-button,
			input.pxui-light-button{background:#4b804b;border-color:#598258;color:#fff;}
        </style>
  </head>
  <body>
   <header id="statusBar">
    <div id="jsheader">
        <nav id="jsnav">
            <a id="jsleft" tapmode="" onclick="api.closeToWin({name: 'root'});">
                <span>主页</span>
            </a>
            <div id="jsmiddle">
                <strong id="jstitle">职场生活</strong>
            </div>
            <a id="jsright">
              <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
            </a>
        </nav>
    </div>
   </header>
  <div class="com-content" style="padding-bottom:0px;margin-bottom: 0px;">
		<!-- <div class="com-header-area" id="js-com-header-area">

			<a href="" class="com-header-logo"
				style="width:100%;color:#FFFFFF;text-align:center;font-size:24px;">职场生活</a>
			<div class="clear"></div>
		</div> -->
		 <div class="com-header-area" id="js-com-header-area" style="padding-bottom:0px;margin-bottom: 0px;">
			<!-- <a href="" class="com-header-logo"
				style="width:100%;color:#FFFFFF;text-align:center;font-size:20px;">职场生活</a> -->
				<img src="../../image/tb.png" style="width:100%;"/>
				<ul class="menu_ul">
					<a href="main.html" class="selected"><li>首  页</li></a>
					<a onclick="goHistory();"><li>历 史 订 单</li></a>
					<a onclick="goBill();"><li>购 物 筐</li></a>
				</ul>
			<dfn></dfn>
			<div class="clear"></div>
		</div>  
		
		<div class="com-content-area" id="js-com-content-area">
			<!--content-->
			<div class="page-role style-page">
				<!-- <div class="pxui-tab pxui-tab-nav pxui-tab-no-top">
					<a href="" onclick="reMain();" class="selected"><i></i>首 页<span></span></a>
					<a href="history.html"><i></i>历史订单<span></span></a>
					<a href="bill.html"><i></i>购物筐<span></span></a>
				</div> -->
				<div class="page-title" style="margin:0px 5px 10px 5px;">
					<a href="#" onclick="closeWin();" class="return">返 回</a>
					<b id="title">

					</b>
				</div>


				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td width="20%" valign="top">
							<div class="pxui-area" id="pxui-area_li" style="border-top-width:0px;">
								<ul class="secli" id="secli">

								</ul>
							</div>
						</td>
						<td valign="top">
							<div class="pxui-area">
								<div class="pxui-shoes">
									<div id="js-goodlist">



									</div>
								</div>
								<div class="pxui-pages" pageurl="?page=@page" pagesize="5" count=""
									url="" container="#js-goodlist">
									<!-- span><i class="arrow-left"></i>&nbsp;&nbsp;上一页</span-->
									<a href="javaScript:void(0)" onclick="jpage('a')"><i class="arrow-left"></i>&nbsp;&nbsp;上一页</a>
									<div class="pxui-select">
										<span id="span_all">1/0</span>
										<del class="arrow-bottom"></del>
										<select id="span_page">
											<option value="1">1/1</option>
										</select>
								</div>
									<a href="javaScript:void(0)" onclick="jpage('b')">下一页&nbsp;&nbsp;<i class="arrow-right"></i></a>
									<!-- span>下一页&nbsp;&nbsp;<i class="arrow-right"></i></span-->
							</div>
						</div>

						</td>
					</tr>
				</table>
		</div>
	</div>
	<!-- 加载动画 -->
	<div id="loadingToast" style="display:none;">
			<div class="weui-mask_transparent"></div>
			<div class="weui-toast">
				<i class="weui-loading weui-icon_toast"></i>
				<p class="weui-toast__content">数据加载中...</p>
			</div>
		</div>
		
	<div style="height: 50px"></div>
<!-- 		<div class="com-footer-area" id="js-com-footer-area">
			<div class="com-footer-nav">
		<a href="main.html">首 页</a>
		<a href="history.html">历史订单</a>
		<a href="bill.html">购物筐</a>
			</div>
			<div class="com-footer">
		 © 2012-2018 四川航天金穗高技术有限公司 <br /> All Rights Reserved
		联系电话：028-66778822
			</div> -->
	<div class="com-footer-area footer" id="js-com-footer" style="width:100%;">
				<img src="../../image/db.png" style="width:100%;"/>
			</div>
	
</div>
	</div>
  </body>
</html>
